home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 10.0 KB | 407 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: BoundShp.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWDSCOPR_H
- #include "FWDscOpr.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawshapes
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(CBoundedShape, CBaseShape)
- FW_DEFINE_AUTO(CBoundedShape)
-
- //========================================================================================
- // class CBoundedShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::CBoundedShape
- //----------------------------------------------------------------------------------------
-
- CBoundedShape::CBoundedShape(CDrawPart* drawPart, unsigned short shapeType, unsigned short renderVerb) :
- CBaseShape(drawPart, 4, shapeType, renderVerb)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::CBoundedShape
- //----------------------------------------------------------------------------------------
-
- CBoundedShape::CBoundedShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
- CBaseShape(drawPart, archive)
- {
- FW_CRect tempRect;
- archive >> tempRect;
-
- SetRectGeometry(tempRect);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::~CBoundedShape
- //----------------------------------------------------------------------------------------
-
- CBoundedShape::~CBoundedShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::GetHandleCenter
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::GetHandleCenter(short whichHandle, FW_CPoint& center) const
- {
- if (fNumberOfHandles == 1)
- whichHandle = kInTopLeftCorner;
- else if (fNumberOfHandles == 2)
- {
- whichHandle = (whichHandle == kInTopLeftCorner) ? kInTopLeftCorner : kInBottomRightCorner;
- }
-
- switch (whichHandle)
- {
- case kInTopLeftCorner:
- center.x = fRect.left;
- center.y = fRect.top;
- break;
- case kInTopRightCorner:
- center.x = fRect.right;
- center.y = fRect.top;
- break;
- case kInBottomLeftCorner:
- center.x = fRect.left;
- center.y = fRect.bottom;
- break;
- case kInBottomRightCorner:
- center.x = fRect.right;
- center.y = fRect.bottom;
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::ResizeFeedback
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::ResizeFeedback(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style,
- short whichHandle, const FW_CPoint& mouseLoc)
- {
- FW_CRect srcRect, dstRect;
- GetMapRects(whichHandle, mouseLoc, srcRect, dstRect);
- dstRect.Sort();
- OutlineShape(gc, ink, style, dstRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::GetMapRects
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::GetMapRects(short whichHandle, const FW_CPoint& mouseLoc,
- FW_CRect& srcRect, FW_CRect& dstRect)
- {
- srcRect = fRect;
- dstRect = srcRect;
-
- switch (whichHandle)
- {
- case kInTopLeftCorner:
- dstRect.left = mouseLoc.x;
- dstRect.top = mouseLoc.y;
- break;
- case kInTopRightCorner:
- dstRect.right = mouseLoc.x;
- dstRect.top = mouseLoc.y;
- break;
- case kInBottomLeftCorner:
- dstRect.left = mouseLoc.x;
- dstRect.bottom = mouseLoc.y;
- break;
- case kInBottomRightCorner:
- dstRect.right = mouseLoc.x;
- dstRect.bottom = mouseLoc.y;
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::MapShape
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::MapShape(Environment *ev, const FW_CRect& srcRect, const FW_CRect& dstRect)
- {
- CheckPromise(ev);
-
- ClearCache(ev);
-
- FW_CRect tempRect = fRect;
- tempRect.Map(srcRect, dstRect);
- tempRect.Sort();
-
- SetRectGeometry(tempRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::OffsetShape
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::OffsetShape(Environment *ev, FW_Fixed xDelta, FW_Fixed yDelta)
- {
- FW_UNUSED(ev);
- // CheckPromise(ev); [HLX] Do not call CheckPromise from OffsetShape or end up in a infinity loop
- // because externalize of a pict calls OffsetShape
- ClearCache(ev);
- FW_CRect tempRect = fRect;
- tempRect.Offset(xDelta, yDelta);
- SetRectGeometry(tempRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::SetShapeGeometry
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::SetShapeGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint)
- {
- FW_CRect tempRect = fRect;
- if (anchorPoint.x < currentPoint.x)
- {
- tempRect.left = anchorPoint.x;
- tempRect.right = currentPoint.x;
- }
- else
- {
- tempRect.left = currentPoint.x;
- tempRect.right = anchorPoint.x;
- }
-
- if (anchorPoint.y < currentPoint.y)
- {
- tempRect.top = anchorPoint.y;
- tempRect.bottom = currentPoint.y;
- }
- else
- {
- tempRect.top = currentPoint.y;
- tempRect.bottom = anchorPoint.y;
- }
-
- SetRectGeometry(tempRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::Flatten(FW_CWritableStream& archive)
- {
- CBaseShape::Flatten(archive);
- archive << fRect;
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::SetRectGeometry
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::SetRectGeometry(const FW_CRect& bounds)
- {
- fRect = bounds;
-
- // Change the number of handles
- if ((fRect.left == fRect.right) && (fRect.top == fRect.bottom))
- {
- fNumberOfHandles = 1;
- }
- if ((fRect.left == fRect.right) || (fRect.top == fRect.bottom))
- {
- fNumberOfHandles = 2;
- }
- else
- fNumberOfHandles = 4;
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::GetRectGeometry
- //----------------------------------------------------------------------------------------
-
- FW_CRect CBoundedShape::GetRectGeometry() const
- {
- return fRect;
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::HasProperty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CBoundedShape::HasProperty(ODDescType whichProperty) const
- {
- FW_Boolean result;
-
- if (whichProperty == pBounds)
- result = TRUE;
- else
- result = CBaseShape::HasProperty(whichProperty);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::GetProperty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CBoundedShape::GetProperty(Environment* ev,
- FW_CPart* part,
- FW_CDesc& propertyValue,
- ODDescType whichProperty,
- ODDescType desiredType) const
- {
- FW_Boolean result;
-
- if (whichProperty == pBounds)
- {
- propertyValue << GetRectGeometry();
- result = TRUE;
- }
- else
- result = CBaseShape::GetProperty(ev, part, propertyValue, whichProperty, desiredType);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CBoundedShape::SetProperty
- //----------------------------------------------------------------------------------------
-
- void CBoundedShape::SetProperty(Environment* ev,
- FW_CPart* part,
- FW_CDesc& propertyValue,
- ODDescType whichProperty)
- {
- if (whichProperty == pBounds)
- {
- FW_CRect newBounds;
-
- propertyValue >> newBounds;
- SetRectGeometry(newBounds);
-
- Invalidate(ev);
- }
- else
- CBaseShape::SetProperty(ev, part, propertyValue, whichProperty);
- }
-